package ml.uuku.swipeheadertabs.ui.fragment.base;

import ml.uuku.swipeheadertabs.R;
import ml.uuku.swipeheadertabs.adapter.ViewPagerFragmentAdapter;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import butterknife.Bind;

/**
 * 带有Tabs和ViewPager的Fragment的基类
 * 
 * @author <a href=http://my.oschina.net/uuku>uuku</a>
 * @version V0.1
 */
public abstract class BaseViewPagerFragment extends BaseFragment {

    @Bind(R.id.tabhost)
    protected TabLayout mTabLayout;
    @Bind(R.id.viewpager)
    protected ViewPager mViewPager;

    @Override
    protected int getLayoutResourceId() {
        return R.layout.base_tabs_viewpager;
    }

    @Override
    public void initView(View rootView) {

        setupViewPager(mViewPager);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void setupViewPager(ViewPager pagers) {
        ViewPagerFragmentAdapter adapter = new ViewPagerFragmentAdapter(getChildFragmentManager());
        setPagerAdapter(adapter);
        pagers.setAdapter(adapter);
    }

    protected abstract void setPagerAdapter(ViewPagerFragmentAdapter pagerAdapter);
}
